const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime,
  pageInfo:pageInfo,
  danciList:danciList,
  saoshiList:saoshiList,
  saveRecord:saveRecord
}
function pageInfo(that){
  wx.request({
    url: 'https://pnst.tsintell.com/content/list', 
    method: 'get',
    data:{
      page:that.data.page
    },
    header: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    success: function (res) {//这里写调用接口成功之后所运行的函数
      if(res.data.code == 200){
        var list =[];
        list.push(res.data.contentDataDOList);
        that.setData({
          contentList:list
        })
      }
    },
    fail: function (res) {//这里写调用接口失败之后所运行的函数
    }
  })
}
function danciList(that){
  wx.request({
    url: 'https://pnst.tsintell.com/content/danci', 
    method: 'get',
    data:{
    nums: that.data.nums
    },
    header: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    success: function (res) {//这里写调用接口成功之后所运行的函数
      if(res.data.code == 200){
        var list =[];
        that.setData({
          danciList:res.data.danciDOList,
        })
      }
    },
    fail: function (res) {//这里写调用接口失败之后所运行的函数
    }
  })
}
function saoshiList(that){
  wx.request({
    url: 'https://pnst.tsintell.com/content/saoshi', 
    method: 'get',
    data:{
    page: that.data.page
    },
    header: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    success: function (res) {//这里写调用接口成功之后所运行的函数
      if(res.data.code == 200){
        var list =[];
        list.push(res.data.saoshiDOList);
        that.setData({
          contentList:list,
        })
      }
    },
    fail: function (res) {//这里写调用接口失败之后所运行的函数
    }
  })
}
function saveRecord(that){
  console.log(that.data);
  wx.request({
    //url: 'http://124.71.238.22:8099/record/save', 
    //url: 'http://localhost:8066/record/save', 
    url: 'https://pnst.tsintell.com/record/save', 
    method: 'POST',
    data:{
    openId: that.data.openId,trainName:that.data.trainName,times:that.data.times,eyeType:that.data.eyeType,equipmentNumber:that.data.equipmentNumber
    },
    header: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    success: function (res) {//这里写调用接口成功之后所运行的函数
      if(res.data.code == 200){
      }
    },
    fail: function (res) {//这里写调用接口失败之后所运行的函数
    }
  })
}
